﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;

using CNCSoft.EWinform;
using CNCSoft.EWinform.ControlUtils;
using CNCSoft.EWinform.ERPApps;
using CNCSoft.EWinform.AGrid;
using CNCSoft.EData;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

using System.Threading;
using System.Globalization;

using Common;

namespace CNCSoft.ErpApps.TMS {

	/// <summary>
	/// Summary description for TienMatPhieuThu.
	/// </summary>
	public class ChungTuKeToan : System.Windows.Forms.Form {
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Label label9;
		internal System.Windows.Forms.Panel pnlButtons;
		internal System.Windows.Forms.Button cmdModify;
		internal System.Windows.Forms.Button cmdCancel;
		internal System.Windows.Forms.Button cmdPrint;
		internal System.Windows.Forms.Button cmdView;
		internal System.Windows.Forms.Button cmdDelete;
        internal System.Windows.Forms.Button cmdAddNew;
		private System.Windows.Forms.TextBox txtNguoiDaiDien;
		private System.Windows.Forms.TextBox txtDienGiai;
		private System.Windows.Forms.TextBox txtChungTuKemTheo;
        private System.Windows.Forms.TextBox txtSoChungTu;
		private System.Windows.Forms.Button cmdXemTK;
		internal System.Windows.Forms.Button cmdUpdate;
		private System.Windows.Forms.TextBox txtDiaChi;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.Windows.Forms.ErrorProvider ep;
		private System.Windows.Forms.Label lblStatus;
		private System.Windows.Forms.Button cmdLookupDVNopTiep;
		private System.Windows.Forms.Panel pnlNevigator;
		internal System.Windows.Forms.Button cmdMovePrevious;
		internal System.Windows.Forms.Button cmdMoveFirst;
		internal System.Windows.Forms.Button cmdMoveLast;
		internal System.Windows.Forms.Button cmdMoveNext;
        private CNCSoft.EWinform.ValidText txtNgayChungTu;
		private System.Windows.Forms.Label lblRecordInfo;
		private System.Windows.Forms.Panel pnlBottom;
		private System.Windows.Forms.PictureBox picboxNote;
        private System.Windows.Forms.PictureBox picboxHelp;
        private TextBox txtSoTien;
        private Label label11;
        private DataGrid dgridChiTietPT;
        private TextBox txtDonVi;
        private Label lblTenDonVi;
		private System.ComponentModel.IContainer components;

        public ChungTuKeToan()
		{
			//
			// Required for Windows Form Designer support
			//

            // Sets the UI culture to VietNamese (VietNam) / English
            if (GlobalVariable.WSInfo.Language == "Tiếng Việt")
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("vi-VN");
            else if (GlobalVariable.WSInfo.Language == "English")
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");

			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChungTuKeToan));
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtNguoiDaiDien = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.txtDienGiai = new System.Windows.Forms.TextBox();
            this.txtChungTuKemTheo = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.txtSoChungTu = new System.Windows.Forms.TextBox();
            this.label9 = new System.Windows.Forms.Label();
            this.pnlButtons = new System.Windows.Forms.Panel();
            this.cmdModify = new System.Windows.Forms.Button();
            this.cmdCancel = new System.Windows.Forms.Button();
            this.cmdPrint = new System.Windows.Forms.Button();
            this.cmdView = new System.Windows.Forms.Button();
            this.cmdDelete = new System.Windows.Forms.Button();
            this.cmdAddNew = new System.Windows.Forms.Button();
            this.cmdUpdate = new System.Windows.Forms.Button();
            this.cmdXemTK = new System.Windows.Forms.Button();
            this.txtDiaChi = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.picboxNote = new System.Windows.Forms.PictureBox();
            this.picboxHelp = new System.Windows.Forms.PictureBox();
            this.cmdLookupDVNopTiep = new System.Windows.Forms.Button();
            this.txtSoTien = new System.Windows.Forms.TextBox();
            this.dgridChiTietPT = new System.Windows.Forms.DataGrid();
            this.lblStatus = new System.Windows.Forms.Label();
            this.pnlBottom = new System.Windows.Forms.Panel();
            this.pnlNevigator = new System.Windows.Forms.Panel();
            this.cmdMoveFirst = new System.Windows.Forms.Button();
            this.cmdMovePrevious = new System.Windows.Forms.Button();
            this.cmdMoveNext = new System.Windows.Forms.Button();
            this.cmdMoveLast = new System.Windows.Forms.Button();
            this.lblRecordInfo = new System.Windows.Forms.Label();
            this.txtNgayChungTu = new CNCSoft.EWinform.ValidText();
            this.label11 = new System.Windows.Forms.Label();
            this.txtDonVi = new System.Windows.Forms.TextBox();
            this.lblTenDonVi = new System.Windows.Forms.Label();
            this.ep = new System.Windows.Forms.ErrorProvider(this.components);
            this.pnlButtons.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.picboxNote)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.picboxHelp)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgridChiTietPT)).BeginInit();
            this.pnlBottom.SuspendLayout();
            this.pnlNevigator.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.ep)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            resources.ApplyResources(this.label1, "label1");
            this.ep.SetError(this.label1, resources.GetString("label1.Error"));
            this.ep.SetIconAlignment(this.label1, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label1.IconAlignment"))));
            this.ep.SetIconPadding(this.label1, ((int)(resources.GetObject("label1.IconPadding"))));
            this.label1.Name = "label1";
            this.toolTip1.SetToolTip(this.label1, resources.GetString("label1.ToolTip"));
            this.label1.Click += new System.EventHandler(this.label1_Click);
            // 
            // label2
            // 
            resources.ApplyResources(this.label2, "label2");
            this.ep.SetError(this.label2, resources.GetString("label2.Error"));
            this.ep.SetIconAlignment(this.label2, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label2.IconAlignment"))));
            this.ep.SetIconPadding(this.label2, ((int)(resources.GetObject("label2.IconPadding"))));
            this.label2.Name = "label2";
            this.toolTip1.SetToolTip(this.label2, resources.GetString("label2.ToolTip"));
            // 
            // txtNguoiDaiDien
            // 
            resources.ApplyResources(this.txtNguoiDaiDien, "txtNguoiDaiDien");
            this.ep.SetError(this.txtNguoiDaiDien, resources.GetString("txtNguoiDaiDien.Error"));
            this.ep.SetIconAlignment(this.txtNguoiDaiDien, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtNguoiDaiDien.IconAlignment"))));
            this.ep.SetIconPadding(this.txtNguoiDaiDien, ((int)(resources.GetObject("txtNguoiDaiDien.IconPadding"))));
            this.txtNguoiDaiDien.Name = "txtNguoiDaiDien";
            this.toolTip1.SetToolTip(this.txtNguoiDaiDien, resources.GetString("txtNguoiDaiDien.ToolTip"));
            // 
            // label3
            // 
            resources.ApplyResources(this.label3, "label3");
            this.ep.SetError(this.label3, resources.GetString("label3.Error"));
            this.ep.SetIconAlignment(this.label3, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label3.IconAlignment"))));
            this.ep.SetIconPadding(this.label3, ((int)(resources.GetObject("label3.IconPadding"))));
            this.label3.Name = "label3";
            this.toolTip1.SetToolTip(this.label3, resources.GetString("label3.ToolTip"));
            this.label3.Click += new System.EventHandler(this.label3_Click);
            // 
            // txtDienGiai
            // 
            resources.ApplyResources(this.txtDienGiai, "txtDienGiai");
            this.ep.SetError(this.txtDienGiai, resources.GetString("txtDienGiai.Error"));
            this.ep.SetIconAlignment(this.txtDienGiai, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtDienGiai.IconAlignment"))));
            this.ep.SetIconPadding(this.txtDienGiai, ((int)(resources.GetObject("txtDienGiai.IconPadding"))));
            this.txtDienGiai.Name = "txtDienGiai";
            this.txtDienGiai.Tag = "<LyDoThu> của <TenDonVi>";
            this.toolTip1.SetToolTip(this.txtDienGiai, resources.GetString("txtDienGiai.ToolTip"));
            this.txtDienGiai.TextChanged += new System.EventHandler(this.txtDienGiai_TextChanged);
            // 
            // txtChungTuKemTheo
            // 
            resources.ApplyResources(this.txtChungTuKemTheo, "txtChungTuKemTheo");
            this.ep.SetError(this.txtChungTuKemTheo, resources.GetString("txtChungTuKemTheo.Error"));
            this.ep.SetIconAlignment(this.txtChungTuKemTheo, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtChungTuKemTheo.IconAlignment"))));
            this.ep.SetIconPadding(this.txtChungTuKemTheo, ((int)(resources.GetObject("txtChungTuKemTheo.IconPadding"))));
            this.txtChungTuKemTheo.Name = "txtChungTuKemTheo";
            this.toolTip1.SetToolTip(this.txtChungTuKemTheo, resources.GetString("txtChungTuKemTheo.ToolTip"));
            // 
            // label5
            // 
            resources.ApplyResources(this.label5, "label5");
            this.ep.SetError(this.label5, resources.GetString("label5.Error"));
            this.ep.SetIconAlignment(this.label5, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label5.IconAlignment"))));
            this.ep.SetIconPadding(this.label5, ((int)(resources.GetObject("label5.IconPadding"))));
            this.label5.Name = "label5";
            this.toolTip1.SetToolTip(this.label5, resources.GetString("label5.ToolTip"));
            this.label5.Click += new System.EventHandler(this.label5_Click);
            // 
            // label8
            // 
            resources.ApplyResources(this.label8, "label8");
            this.ep.SetError(this.label8, resources.GetString("label8.Error"));
            this.ep.SetIconAlignment(this.label8, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label8.IconAlignment"))));
            this.ep.SetIconPadding(this.label8, ((int)(resources.GetObject("label8.IconPadding"))));
            this.label8.Name = "label8";
            this.toolTip1.SetToolTip(this.label8, resources.GetString("label8.ToolTip"));
            // 
            // txtSoChungTu
            // 
            resources.ApplyResources(this.txtSoChungTu, "txtSoChungTu");
            this.ep.SetError(this.txtSoChungTu, resources.GetString("txtSoChungTu.Error"));
            this.txtSoChungTu.ForeColor = System.Drawing.Color.ForestGreen;
            this.ep.SetIconAlignment(this.txtSoChungTu, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtSoChungTu.IconAlignment"))));
            this.ep.SetIconPadding(this.txtSoChungTu, ((int)(resources.GetObject("txtSoChungTu.IconPadding"))));
            this.txtSoChungTu.Name = "txtSoChungTu";
            this.txtSoChungTu.TabStop = false;
            this.toolTip1.SetToolTip(this.txtSoChungTu, resources.GetString("txtSoChungTu.ToolTip"));
            // 
            // label9
            // 
            resources.ApplyResources(this.label9, "label9");
            this.ep.SetError(this.label9, resources.GetString("label9.Error"));
            this.ep.SetIconAlignment(this.label9, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label9.IconAlignment"))));
            this.ep.SetIconPadding(this.label9, ((int)(resources.GetObject("label9.IconPadding"))));
            this.label9.Name = "label9";
            this.toolTip1.SetToolTip(this.label9, resources.GetString("label9.ToolTip"));
            // 
            // pnlButtons
            // 
            resources.ApplyResources(this.pnlButtons, "pnlButtons");
            this.pnlButtons.Controls.Add(this.cmdModify);
            this.pnlButtons.Controls.Add(this.cmdCancel);
            this.pnlButtons.Controls.Add(this.cmdPrint);
            this.pnlButtons.Controls.Add(this.cmdView);
            this.pnlButtons.Controls.Add(this.cmdDelete);
            this.pnlButtons.Controls.Add(this.cmdAddNew);
            this.pnlButtons.Controls.Add(this.cmdUpdate);
            this.ep.SetError(this.pnlButtons, resources.GetString("pnlButtons.Error"));
            this.ep.SetIconAlignment(this.pnlButtons, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("pnlButtons.IconAlignment"))));
            this.ep.SetIconPadding(this.pnlButtons, ((int)(resources.GetObject("pnlButtons.IconPadding"))));
            this.pnlButtons.Name = "pnlButtons";
            this.toolTip1.SetToolTip(this.pnlButtons, resources.GetString("pnlButtons.ToolTip"));
            // 
            // cmdModify
            // 
            resources.ApplyResources(this.cmdModify, "cmdModify");
            this.cmdModify.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdModify, resources.GetString("cmdModify.Error"));
            this.cmdModify.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdModify, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdModify.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdModify, ((int)(resources.GetObject("cmdModify.IconPadding"))));
            this.cmdModify.Name = "cmdModify";
            this.toolTip1.SetToolTip(this.cmdModify, resources.GetString("cmdModify.ToolTip"));
            this.cmdModify.Click += new System.EventHandler(this.cmdModify_Click);
            // 
            // cmdCancel
            // 
            resources.ApplyResources(this.cmdCancel, "cmdCancel");
            this.cmdCancel.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdCancel, resources.GetString("cmdCancel.Error"));
            this.cmdCancel.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdCancel, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdCancel.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdCancel, ((int)(resources.GetObject("cmdCancel.IconPadding"))));
            this.cmdCancel.Name = "cmdCancel";
            this.toolTip1.SetToolTip(this.cmdCancel, resources.GetString("cmdCancel.ToolTip"));
            this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
            // 
            // cmdPrint
            // 
            resources.ApplyResources(this.cmdPrint, "cmdPrint");
            this.cmdPrint.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdPrint, resources.GetString("cmdPrint.Error"));
            this.cmdPrint.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdPrint, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdPrint.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdPrint, ((int)(resources.GetObject("cmdPrint.IconPadding"))));
            this.cmdPrint.Name = "cmdPrint";
            this.toolTip1.SetToolTip(this.cmdPrint, resources.GetString("cmdPrint.ToolTip"));
            this.cmdPrint.Click += new System.EventHandler(this.cmdPrint_Click);
            // 
            // cmdView
            // 
            resources.ApplyResources(this.cmdView, "cmdView");
            this.cmdView.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdView, resources.GetString("cmdView.Error"));
            this.cmdView.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdView, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdView.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdView, ((int)(resources.GetObject("cmdView.IconPadding"))));
            this.cmdView.Name = "cmdView";
            this.toolTip1.SetToolTip(this.cmdView, resources.GetString("cmdView.ToolTip"));
            this.cmdView.Click += new System.EventHandler(this.cmdView_Click);
            // 
            // cmdDelete
            // 
            resources.ApplyResources(this.cmdDelete, "cmdDelete");
            this.cmdDelete.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdDelete, resources.GetString("cmdDelete.Error"));
            this.cmdDelete.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdDelete, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdDelete.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdDelete, ((int)(resources.GetObject("cmdDelete.IconPadding"))));
            this.cmdDelete.Name = "cmdDelete";
            this.toolTip1.SetToolTip(this.cmdDelete, resources.GetString("cmdDelete.ToolTip"));
            this.cmdDelete.Click += new System.EventHandler(this.cmdDelete_Click);
            // 
            // cmdAddNew
            // 
            resources.ApplyResources(this.cmdAddNew, "cmdAddNew");
            this.cmdAddNew.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdAddNew, resources.GetString("cmdAddNew.Error"));
            this.cmdAddNew.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdAddNew, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdAddNew.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdAddNew, ((int)(resources.GetObject("cmdAddNew.IconPadding"))));
            this.cmdAddNew.Name = "cmdAddNew";
            this.toolTip1.SetToolTip(this.cmdAddNew, resources.GetString("cmdAddNew.ToolTip"));
            this.cmdAddNew.Click += new System.EventHandler(this.cmdAddNew_Click);
            // 
            // cmdUpdate
            // 
            resources.ApplyResources(this.cmdUpdate, "cmdUpdate");
            this.cmdUpdate.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdUpdate, resources.GetString("cmdUpdate.Error"));
            this.cmdUpdate.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdUpdate, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdUpdate.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdUpdate, ((int)(resources.GetObject("cmdUpdate.IconPadding"))));
            this.cmdUpdate.Name = "cmdUpdate";
            this.toolTip1.SetToolTip(this.cmdUpdate, resources.GetString("cmdUpdate.ToolTip"));
            this.cmdUpdate.Click += new System.EventHandler(this.cmdSave_Click);
            // 
            // cmdXemTK
            // 
            resources.ApplyResources(this.cmdXemTK, "cmdXemTK");
            this.cmdXemTK.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdXemTK, resources.GetString("cmdXemTK.Error"));
            this.cmdXemTK.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdXemTK, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdXemTK.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdXemTK, ((int)(resources.GetObject("cmdXemTK.IconPadding"))));
            this.cmdXemTK.Name = "cmdXemTK";
            this.cmdXemTK.TabStop = false;
            this.toolTip1.SetToolTip(this.cmdXemTK, resources.GetString("cmdXemTK.ToolTip"));
            this.cmdXemTK.Click += new System.EventHandler(this.cmdXemTK_Click);
            // 
            // txtDiaChi
            // 
            resources.ApplyResources(this.txtDiaChi, "txtDiaChi");
            this.ep.SetError(this.txtDiaChi, resources.GetString("txtDiaChi.Error"));
            this.ep.SetIconAlignment(this.txtDiaChi, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtDiaChi.IconAlignment"))));
            this.ep.SetIconPadding(this.txtDiaChi, ((int)(resources.GetObject("txtDiaChi.IconPadding"))));
            this.txtDiaChi.Name = "txtDiaChi";
            this.toolTip1.SetToolTip(this.txtDiaChi, resources.GetString("txtDiaChi.ToolTip"));
            // 
            // label6
            // 
            resources.ApplyResources(this.label6, "label6");
            this.ep.SetError(this.label6, resources.GetString("label6.Error"));
            this.ep.SetIconAlignment(this.label6, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label6.IconAlignment"))));
            this.ep.SetIconPadding(this.label6, ((int)(resources.GetObject("label6.IconPadding"))));
            this.label6.Name = "label6";
            this.toolTip1.SetToolTip(this.label6, resources.GetString("label6.ToolTip"));
            this.label6.Click += new System.EventHandler(this.label6_Click);
            // 
            // picboxNote
            // 
            resources.ApplyResources(this.picboxNote, "picboxNote");
            this.picboxNote.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.picboxNote, resources.GetString("picboxNote.Error"));
            this.ep.SetIconAlignment(this.picboxNote, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("picboxNote.IconAlignment"))));
            this.ep.SetIconPadding(this.picboxNote, ((int)(resources.GetObject("picboxNote.IconPadding"))));
            this.picboxNote.Name = "picboxNote";
            this.picboxNote.TabStop = false;
            this.toolTip1.SetToolTip(this.picboxNote, resources.GetString("picboxNote.ToolTip"));
            this.picboxNote.Click += new System.EventHandler(this.cmdNote_Click);
            // 
            // picboxHelp
            // 
            resources.ApplyResources(this.picboxHelp, "picboxHelp");
            this.picboxHelp.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.picboxHelp, resources.GetString("picboxHelp.Error"));
            this.ep.SetIconAlignment(this.picboxHelp, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("picboxHelp.IconAlignment"))));
            this.ep.SetIconPadding(this.picboxHelp, ((int)(resources.GetObject("picboxHelp.IconPadding"))));
            this.picboxHelp.Name = "picboxHelp";
            this.picboxHelp.TabStop = false;
            this.toolTip1.SetToolTip(this.picboxHelp, resources.GetString("picboxHelp.ToolTip"));
            // 
            // cmdLookupDVNopTiep
            // 
            resources.ApplyResources(this.cmdLookupDVNopTiep, "cmdLookupDVNopTiep");
            this.cmdLookupDVNopTiep.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdLookupDVNopTiep, resources.GetString("cmdLookupDVNopTiep.Error"));
            this.cmdLookupDVNopTiep.ForeColor = System.Drawing.Color.DodgerBlue;
            this.ep.SetIconAlignment(this.cmdLookupDVNopTiep, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdLookupDVNopTiep.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdLookupDVNopTiep, ((int)(resources.GetObject("cmdLookupDVNopTiep.IconPadding"))));
            this.cmdLookupDVNopTiep.Name = "cmdLookupDVNopTiep";
            this.cmdLookupDVNopTiep.TabStop = false;
            this.toolTip1.SetToolTip(this.cmdLookupDVNopTiep, resources.GetString("cmdLookupDVNopTiep.ToolTip"));
            this.cmdLookupDVNopTiep.Click += new System.EventHandler(this.cmdLookupDVNopTiep_Click);
            // 
            // txtSoTien
            // 
            resources.ApplyResources(this.txtSoTien, "txtSoTien");
            this.txtSoTien.BackColor = System.Drawing.Color.PaleGoldenrod;
            this.ep.SetError(this.txtSoTien, resources.GetString("txtSoTien.Error"));
            this.txtSoTien.ForeColor = System.Drawing.Color.IndianRed;
            this.ep.SetIconAlignment(this.txtSoTien, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtSoTien.IconAlignment"))));
            this.ep.SetIconPadding(this.txtSoTien, ((int)(resources.GetObject("txtSoTien.IconPadding"))));
            this.txtSoTien.Name = "txtSoTien";
            this.toolTip1.SetToolTip(this.txtSoTien, resources.GetString("txtSoTien.ToolTip"));
            this.txtSoTien.Validated += new System.EventHandler(this.txtSoTien_Validated);
            // 
            // dgridChiTietPT
            // 
            resources.ApplyResources(this.dgridChiTietPT, "dgridChiTietPT");
            this.dgridChiTietPT.AllowSorting = false;
            this.dgridChiTietPT.CaptionVisible = false;
            this.dgridChiTietPT.DataMember = "";
            this.ep.SetError(this.dgridChiTietPT, resources.GetString("dgridChiTietPT.Error"));
            this.dgridChiTietPT.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.ep.SetIconAlignment(this.dgridChiTietPT, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("dgridChiTietPT.IconAlignment"))));
            this.ep.SetIconPadding(this.dgridChiTietPT, ((int)(resources.GetObject("dgridChiTietPT.IconPadding"))));
            this.dgridChiTietPT.Name = "dgridChiTietPT";
            this.toolTip1.SetToolTip(this.dgridChiTietPT, resources.GetString("dgridChiTietPT.ToolTip"));
            this.dgridChiTietPT.Validated += new System.EventHandler(this.dgridChiTietPT_Validated);
            // 
            // lblStatus
            // 
            resources.ApplyResources(this.lblStatus, "lblStatus");
            this.ep.SetError(this.lblStatus, resources.GetString("lblStatus.Error"));
            this.ep.SetIconAlignment(this.lblStatus, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("lblStatus.IconAlignment"))));
            this.ep.SetIconPadding(this.lblStatus, ((int)(resources.GetObject("lblStatus.IconPadding"))));
            this.lblStatus.Name = "lblStatus";
            this.toolTip1.SetToolTip(this.lblStatus, resources.GetString("lblStatus.ToolTip"));
            // 
            // pnlBottom
            // 
            resources.ApplyResources(this.pnlBottom, "pnlBottom");
            this.pnlBottom.Controls.Add(this.picboxNote);
            this.pnlBottom.Controls.Add(this.picboxHelp);
            this.pnlBottom.Controls.Add(this.lblStatus);
            this.pnlBottom.Controls.Add(this.pnlNevigator);
            this.ep.SetError(this.pnlBottom, resources.GetString("pnlBottom.Error"));
            this.ep.SetIconAlignment(this.pnlBottom, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("pnlBottom.IconAlignment"))));
            this.ep.SetIconPadding(this.pnlBottom, ((int)(resources.GetObject("pnlBottom.IconPadding"))));
            this.pnlBottom.Name = "pnlBottom";
            this.toolTip1.SetToolTip(this.pnlBottom, resources.GetString("pnlBottom.ToolTip"));
            // 
            // pnlNevigator
            // 
            resources.ApplyResources(this.pnlNevigator, "pnlNevigator");
            this.pnlNevigator.Controls.Add(this.cmdMoveFirst);
            this.pnlNevigator.Controls.Add(this.cmdMovePrevious);
            this.pnlNevigator.Controls.Add(this.cmdMoveNext);
            this.pnlNevigator.Controls.Add(this.cmdMoveLast);
            this.pnlNevigator.Controls.Add(this.lblRecordInfo);
            this.ep.SetError(this.pnlNevigator, resources.GetString("pnlNevigator.Error"));
            this.ep.SetIconAlignment(this.pnlNevigator, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("pnlNevigator.IconAlignment"))));
            this.ep.SetIconPadding(this.pnlNevigator, ((int)(resources.GetObject("pnlNevigator.IconPadding"))));
            this.pnlNevigator.Name = "pnlNevigator";
            this.toolTip1.SetToolTip(this.pnlNevigator, resources.GetString("pnlNevigator.ToolTip"));
            // 
            // cmdMoveFirst
            // 
            resources.ApplyResources(this.cmdMoveFirst, "cmdMoveFirst");
            this.cmdMoveFirst.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdMoveFirst, resources.GetString("cmdMoveFirst.Error"));
            this.cmdMoveFirst.ForeColor = System.Drawing.Color.Maroon;
            this.ep.SetIconAlignment(this.cmdMoveFirst, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdMoveFirst.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdMoveFirst, ((int)(resources.GetObject("cmdMoveFirst.IconPadding"))));
            this.cmdMoveFirst.Name = "cmdMoveFirst";
            this.toolTip1.SetToolTip(this.cmdMoveFirst, resources.GetString("cmdMoveFirst.ToolTip"));
            this.cmdMoveFirst.Click += new System.EventHandler(this.cmdMoveFirst_Click);
            // 
            // cmdMovePrevious
            // 
            resources.ApplyResources(this.cmdMovePrevious, "cmdMovePrevious");
            this.cmdMovePrevious.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdMovePrevious, resources.GetString("cmdMovePrevious.Error"));
            this.cmdMovePrevious.ForeColor = System.Drawing.Color.Maroon;
            this.ep.SetIconAlignment(this.cmdMovePrevious, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdMovePrevious.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdMovePrevious, ((int)(resources.GetObject("cmdMovePrevious.IconPadding"))));
            this.cmdMovePrevious.Name = "cmdMovePrevious";
            this.toolTip1.SetToolTip(this.cmdMovePrevious, resources.GetString("cmdMovePrevious.ToolTip"));
            this.cmdMovePrevious.Click += new System.EventHandler(this.cmdMovePrevious_Click);
            // 
            // cmdMoveNext
            // 
            resources.ApplyResources(this.cmdMoveNext, "cmdMoveNext");
            this.cmdMoveNext.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdMoveNext, resources.GetString("cmdMoveNext.Error"));
            this.cmdMoveNext.ForeColor = System.Drawing.Color.Maroon;
            this.ep.SetIconAlignment(this.cmdMoveNext, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdMoveNext.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdMoveNext, ((int)(resources.GetObject("cmdMoveNext.IconPadding"))));
            this.cmdMoveNext.Name = "cmdMoveNext";
            this.toolTip1.SetToolTip(this.cmdMoveNext, resources.GetString("cmdMoveNext.ToolTip"));
            this.cmdMoveNext.Click += new System.EventHandler(this.cmdMoveNext_Click);
            // 
            // cmdMoveLast
            // 
            resources.ApplyResources(this.cmdMoveLast, "cmdMoveLast");
            this.cmdMoveLast.Cursor = System.Windows.Forms.Cursors.Hand;
            this.ep.SetError(this.cmdMoveLast, resources.GetString("cmdMoveLast.Error"));
            this.cmdMoveLast.ForeColor = System.Drawing.Color.Maroon;
            this.ep.SetIconAlignment(this.cmdMoveLast, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("cmdMoveLast.IconAlignment"))));
            this.ep.SetIconPadding(this.cmdMoveLast, ((int)(resources.GetObject("cmdMoveLast.IconPadding"))));
            this.cmdMoveLast.Name = "cmdMoveLast";
            this.toolTip1.SetToolTip(this.cmdMoveLast, resources.GetString("cmdMoveLast.ToolTip"));
            this.cmdMoveLast.Click += new System.EventHandler(this.cmdMoveLast_Click);
            // 
            // lblRecordInfo
            // 
            resources.ApplyResources(this.lblRecordInfo, "lblRecordInfo");
            this.lblRecordInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.ep.SetError(this.lblRecordInfo, resources.GetString("lblRecordInfo.Error"));
            this.ep.SetIconAlignment(this.lblRecordInfo, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("lblRecordInfo.IconAlignment"))));
            this.ep.SetIconPadding(this.lblRecordInfo, ((int)(resources.GetObject("lblRecordInfo.IconPadding"))));
            this.lblRecordInfo.Name = "lblRecordInfo";
            this.toolTip1.SetToolTip(this.lblRecordInfo, resources.GetString("lblRecordInfo.ToolTip"));
            // 
            // txtNgayChungTu
            // 
            resources.ApplyResources(this.txtNgayChungTu, "txtNgayChungTu");
            this.txtNgayChungTu.ClearTime = false;
            this.txtNgayChungTu.DateDelimiter = "/";
            this.txtNgayChungTu.DateInputFormat = CNCSoft.EUtilities.DateFormat.DDMMYYYY;
            this.txtNgayChungTu.DateOutputFormat = CNCSoft.EUtilities.DateFormat.DDMMYYYY;
            this.ep.SetError(this.txtNgayChungTu, resources.GetString("txtNgayChungTu.Error"));
            this.txtNgayChungTu.FieldReference = null;
            this.ep.SetIconAlignment(this.txtNgayChungTu, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtNgayChungTu.IconAlignment"))));
            this.ep.SetIconPadding(this.txtNgayChungTu, ((int)(resources.GetObject("txtNgayChungTu.IconPadding"))));
            this.txtNgayChungTu.MaskEdit = "";
            this.txtNgayChungTu.MessageLanguage = CNCSoft.EWinform.ValidText.MessageLanguages.Vietnamese;
            this.txtNgayChungTu.Name = "txtNgayChungTu";
            this.txtNgayChungTu.RegExPattern = CNCSoft.EWinform.ValidText.RegularExpressionModes.AutomatedDate;
            this.txtNgayChungTu.Required = false;
            this.txtNgayChungTu.ShowErrorIcon = true;
            this.toolTip1.SetToolTip(this.txtNgayChungTu, resources.GetString("txtNgayChungTu.ToolTip"));
            this.txtNgayChungTu.ValidationMode = CNCSoft.EWinform.ValidText.ValidationModes.None;
            this.txtNgayChungTu.ValidText = "0123456789/ ";
            this.txtNgayChungTu.YearPrefix = ((short)(20));
            // 
            // label11
            // 
            resources.ApplyResources(this.label11, "label11");
            this.ep.SetError(this.label11, resources.GetString("label11.Error"));
            this.ep.SetIconAlignment(this.label11, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("label11.IconAlignment"))));
            this.ep.SetIconPadding(this.label11, ((int)(resources.GetObject("label11.IconPadding"))));
            this.label11.Name = "label11";
            this.toolTip1.SetToolTip(this.label11, resources.GetString("label11.ToolTip"));
            this.label11.Click += new System.EventHandler(this.label11_Click);
            // 
            // txtDonVi
            // 
            resources.ApplyResources(this.txtDonVi, "txtDonVi");
            this.ep.SetError(this.txtDonVi, resources.GetString("txtDonVi.Error"));
            this.ep.SetIconAlignment(this.txtDonVi, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("txtDonVi.IconAlignment"))));
            this.ep.SetIconPadding(this.txtDonVi, ((int)(resources.GetObject("txtDonVi.IconPadding"))));
            this.txtDonVi.Name = "txtDonVi";
            this.toolTip1.SetToolTip(this.txtDonVi, resources.GetString("txtDonVi.ToolTip"));
            this.txtDonVi.TextChanged += new System.EventHandler(this.txtDonVi_TextChanged);
            this.txtDonVi.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDonVi_KeyDown);
            this.txtDonVi.Validated += new System.EventHandler(this.txtDonVi_Validated);
            // 
            // lblTenDonVi
            // 
            resources.ApplyResources(this.lblTenDonVi, "lblTenDonVi");
            this.ep.SetError(this.lblTenDonVi, resources.GetString("lblTenDonVi.Error"));
            this.ep.SetIconAlignment(this.lblTenDonVi, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("lblTenDonVi.IconAlignment"))));
            this.ep.SetIconPadding(this.lblTenDonVi, ((int)(resources.GetObject("lblTenDonVi.IconPadding"))));
            this.lblTenDonVi.Name = "lblTenDonVi";
            this.toolTip1.SetToolTip(this.lblTenDonVi, resources.GetString("lblTenDonVi.ToolTip"));
            // 
            // ep
            // 
            this.ep.ContainerControl = this;
            resources.ApplyResources(this.ep, "ep");
            // 
            // ChungTuKeToan
            // 
            resources.ApplyResources(this, "$this");
            this.BackColor = System.Drawing.Color.WhiteSmoke;
            this.Controls.Add(this.lblTenDonVi);
            this.Controls.Add(this.txtNguoiDaiDien);
            this.Controls.Add(this.cmdLookupDVNopTiep);
            this.Controls.Add(this.txtDonVi);
            this.Controls.Add(this.txtSoTien);
            this.Controls.Add(this.label11);
            this.Controls.Add(this.txtNgayChungTu);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.txtDiaChi);
            this.Controls.Add(this.txtSoChungTu);
            this.Controls.Add(this.txtChungTuKemTheo);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.txtDienGiai);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.label9);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.cmdXemTK);
            this.Controls.Add(this.pnlButtons);
            this.Controls.Add(this.pnlBottom);
            this.Controls.Add(this.dgridChiTietPT);
            this.KeyPreview = true;
            this.Name = "ChungTuKeToan";
            this.Tag = "";
            this.toolTip1.SetToolTip(this, resources.GetString("$this.ToolTip"));
            this.Load += new System.EventHandler(this.ChungTuKeToan_Load);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TienMatPhieuThu_KeyDown);
            this.pnlButtons.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.picboxNote)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.picboxHelp)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgridChiTietPT)).EndInit();
            this.pnlBottom.ResumeLayout(false);
            this.pnlNevigator.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.ep)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		#region [ Command Events ]
		
        bool cancelHandlers;
		ChungTuKeToanData ktData;
		BindingManagerBase bmb;
		
        #endregion


        private void ChungTuKeToan_Load(object sender, EventArgs e)
        {
            cancelHandlers = true;
            try
            {
                ktData = new ChungTuKeToanData();

                intiDatabinding();

                ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).ColumnChanged += new DataColumnChangeEventHandler(ChungTuKeToan_ColumnChanged);
                ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).RowDeleted += new DataRowChangeEventHandler(ChungTuKeToan_RowDeleted);

                bmb = this.BindingContext[ktData.getDataSet(), "TienMatPT"];

                bmb.PositionChanged += new EventHandler(bmb_PositionChanged);

            }
            catch
            {
                MessageBox.Show(this, RS.ERROR_LOAD_FORM, RS.ERROR_LOAD_FORM_CAPTION,
                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            }
            finally
            {
                cancelHandlers = false;
            }

            cmdAddNew_Click(cmdAddNew, e);
            //sendStatus("" +(int)Shortcut.Ins, false);
        }


		private void bmb_PositionChanged(object sender, System.EventArgs e) {
			if (cancelHandlers) return;

			cancelHandlers = true;
			if (bmb.Count == 0) {
				this.lblRecordInfo.Text = "0/0";
			} else {
				this.lblRecordInfo.Text = (bmb.Position +1) +"/" +bmb.Count;
			}

			if (bmb.Position >= 0) {
				buildDgridTS();
			}
			cancelHandlers = false;
            
            try
            {
                lblTenDonVi.Text = SQLHelper.ExecuteScalar(GlobalVariable.WSInfo.ConnectionString, "SELECT TenDoiTac FROM DM_DOITAC WHERE MaDoiTac= '" + txtDonVi.Text + "'").ToString();
            }
            catch { }
		}

        private void ChungTuKeToan_RowDeleted(object sender, DataRowChangeEventArgs e)
        {
            if (ktData.getTable(ChungTuKeToanData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D").Length > 0)
            {
                this["TongTien"] = ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).Compute("Sum(SoTien)", "SoChungTu='" + this["SoChungTu"] + "'");
			} else {
			   this["TongTien"] = 0;
			}
			bmb.EndCurrentEdit();
		}
        
        private void ChungTuKeToan_ColumnChanged(object sender, DataColumnChangeEventArgs e)
        {
            //Chu y: O day tinh nhieu khi chua het. Phai tinh them trong Validate cau DataGrid
            if (cancelHandlers) return;
            cancelHandlers = true;
            try
            {
                if (e.Column.ColumnName.ToUpper() == "SOTIEN")
                {
                    double sumSoTien = 0;
                    sumSoTien = (double)(decimal)ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).Compute("Sum(SoTien)", "SoChungTu='" + this["SoChungTu"] + "'");
                    txtSoTien.Text = sumSoTien.ToString("N");
                    bmb.EndCurrentEdit();
                }
            }
            catch { }
            finally
            {
                cancelHandlers = false;
            }
		}

		#region [ Commond Methods ]

		private void intiDatabinding() {
			this.txtSoChungTu.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.SoChungTu");
            this.txtNgayChungTu.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.NgayChungTu");
			this.txtNgayChungTu.ActiveDisplayFormat();
            this.txtDonVi.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.MaDoiTac");
            this.txtNguoiDaiDien.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.Hoten");
            this.txtDiaChi.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.DiaChi");
            this.txtDienGiai.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.DienGiai");
            this.txtChungTuKemTheo.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.SoChungtuKemTheo");

            this.txtSoTien.DataBindings.Add("Text", ktData.getDataSet(), "TienMatPT.TongTien");
            this.txtSoTien.DataBindings["Text"].Parse += new ConvertEventHandler(ChungTuKeToan_Parse);
            this.txtSoTien.DataBindings["Text"].Format += new ConvertEventHandler(ChungTuKeToan_Format);


			dgridChiTietPT.SetDataBinding(ktData.getDataSet(), "TienMatPT.M_D");
		}

        private void ChungTuKeToan_Parse(object sender, ConvertEventArgs e)
        {
			try {
				if (e.Value == null || (string)e.Value == string.Empty) {
					e.Value = DBNull.Value;
				} else {
					e.Value = double.Parse((string)e.Value);
				}
			} catch {
				sendStatus("Bạn vui lòng nhập đúng định dạng số.", true);
			}
		}

        private void ChungTuKeToan_Format(object sender, ConvertEventArgs e)
        {
			try {
				if (Convert.IsDBNull(e.Value)) {
					e.Value = "";
				} else {
					e.Value = ((decimal)e.Value).ToString("N");
				}
			} catch (Exception ex) {
				//sendStatus("Unexpected Error: " +ex.Message, true);  //Ko can thiet
			}
		}

		DataGridAutoResizeSupporter dgridARS = new DataGridAutoResizeSupporter();
		DataGridStyleFactory dgridSF = new DataGridStyleFactory();
	
        private void buildDgridTS() {

			DataGridTableStyle ts = new DataGridTableStyle();
            ts.MappingName = ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).TableName;

            //Them cot TK NO
            AGridMCComBoBoxColumn agridTKNO = new AGridMCComBoBoxColumn(ktData.getTable(ChungTuKeToanData.TL.TaiKhoan));
            agridTKNO.MappingName = "TaiKhoanNo";
            agridTKNO.HeaderText = "Ghi NỢ";
            agridTKNO.DisplayMember = "MaTaiKhoan";
            agridTKNO.ValueMember = "MaTaiKhoan";
            agridTKNO.NullText = "";
            agridTKNO.Width = 100;
            ts.GridColumnStyles.Add(agridTKNO);

            //Them cot TieuKhoanNO1
            AGridMCComBoBoxColumn agridTKNO1 = new AGridMCComBoBoxColumn(ktData.getTable(ChungTuKeToanData.TL.DoiTac));
            agridTKNO1.MappingName = "MaTieuKhoanNo1";
            agridTKNO1.HeaderText = "Tiểu khoản NỢ";
            agridTKNO1.DisplayMember = "MaDoiTac";
            agridTKNO1.ValueMember = "MaDoiTac";
            agridTKNO1.NullText = "";
            agridTKNO1.Width = 100;
            ts.GridColumnStyles.Add(agridTKNO1); 
            
            //Tai khoan CO
            AGridMCComBoBoxColumn agridTKCO = new AGridMCComBoBoxColumn(ktData.getTable(ChungTuKeToanData.TL.TaiKhoan));
            agridTKCO.MappingName = "TaiKhoanCo";
            agridTKCO.HeaderText = "Ghi CÓ";
            agridTKCO.DisplayMember = "MaTaiKhoan";
            agridTKCO.ValueMember = "MaTaiKhoan";
            agridTKCO.NullText = "";
            agridTKCO.Width = 100;
            ts.GridColumnStyles.Add(agridTKCO);
            
            //Them cot TieuKhoanCO1
            AGridMCComBoBoxColumn agridTKCO1 = new AGridMCComBoBoxColumn(ktData.getTable(ChungTuKeToanData.TL.DoiTac));
            agridTKCO1.MappingName = "MaTieuKhoanCo1";
            agridTKCO1.HeaderText = "Tiểu khoản CÓ";
            agridTKCO1.DisplayMember = "MaDoiTac";
            agridTKCO1.ValueMember = "MaDoiTac";
            agridTKCO1.NullText = "";
            agridTKCO1.Width = 100;
            ts.GridColumnStyles.Add(agridTKCO1); 

            AGridTextBoxColumn agridTC;
            //So tien
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "SoTien";
            agridTC.HeaderText = "Số tiền";
            agridTC.NullText = "";
            agridTC.Width = 100;
            agridTC.Format = "N";
            ts.GridColumnStyles.Add(agridTC);

			//Dien giai
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "DienGiaiChiTiet";
            agridTC.HeaderText = "Diễn giải chi tiết";
            agridTC.NullText = "";
            agridTC.Width = 300;
            agridTC.Format = "N";
            ts.GridColumnStyles.Add(agridTC);

            dgridChiTietPT.TableStyles.Clear();
			dgridChiTietPT.TableStyles.Add(ts);
			dgridSF.applyStyle(dgridChiTietPT, DataGridStyleFactory.Styles.SexyStyle);
			dgridChiTietPT.TableStyles[0].AllowSorting = false;
		}

		private void setEditMode(bool edit) {

			cmdAddNew.Enabled = !edit;
			cmdDelete.Enabled = !edit && bmb.Position >= 0;
			cmdModify.Enabled = !edit && bmb.Position >= 0;
			cmdPrint.Enabled = !edit && bmb.Position >= 0;
			cmdView.Enabled = !edit;
			cmdUpdate.Enabled = edit;
			cmdCancel.Enabled = edit;

			cmdLookupDVNopTiep.Enabled = edit;

			cmdMoveFirst.Enabled = !edit;
			cmdMovePrevious.Enabled = !edit;
			cmdMoveNext.Enabled = !edit;
			cmdMoveLast.Enabled = !edit;

			txtSoChungTu.ReadOnly = true;
			txtNgayChungTu.ReadOnly = !edit;
			txtSoTien.ReadOnly = !edit;
			txtDiaChi.ReadOnly = !edit;
			txtDienGiai.ReadOnly = !edit;
			txtChungTuKemTheo.ReadOnly = !edit;
			txtNguoiDaiDien.ReadOnly = !edit;
			txtDonVi.Enabled = edit;
			dgridChiTietPT.ReadOnly = !edit;
			cmdXemTK.Enabled = bmb.Position >= 0;
		}

		#endregion

		#region [ Command Events ]

		private void cmdAddNew_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;

            if (ktData.createNewRow())
            {
				bmb.Position = bmb.Count -1;
				setEditMode(true);
				txtDonVi.Focus();
			}
			cancelHandlers= false;
			bmb_PositionChanged(bmb, e);
			sendStatus("Đang trong trạng thái thêm mới...", false);

		}

		private void cmdSave_Click(object sender, System.EventArgs e) {

            ep.Clear();
            //Kiem tra su giong nhau giua sochungtu va ngaychungtu
            if (txtNgayChungTu.getDateValue(true).Year.ToString().Substring(2, 2) != txtSoChungTu.Text.Substring(2, 2) || txtNgayChungTu.getDateValue(true).Month.ToString("00") != txtSoChungTu.Text.Substring(4, 2))
            {
                MessageBox.Show("Thời gian làm việc không đúng với ngày chứng từ \nBạn phải login vào chương trình với ngày làm việc thuộc tháng " +
                                              txtNgayChungTu.getDateValue(true).Month.ToString() + " năm " + txtNgayChungTu.getDateValue(true).Year.ToString(),
                                              "Chon sai ngay lam viec", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ep.SetError(txtSoChungTu, "Chọn lại ngày làm việc ngay ở màn hình đăng nhập ban đầu để đánh số chứng từ cho đúng");
                return;
            }
            //Kiem tra cac field can thiet
            
            if (txtDonVi.Text == "") {
				ep.SetError(txtDonVi, "Bạn vui lòng chọn đơn vị nộp tiền.");
				txtDonVi.Focus();
				showEP = true;
				return;
			}
			// dont regard to this code
			try {
				dgridChiTietPT.CurrentCell = 
					new DataGridCell(dgridChiTietPT.CurrentCell.RowNumber +1, 
					dgridChiTietPT.CurrentCell.ColumnNumber);
			} catch {}

			cancelHandlers = true;
			bmb.EndCurrentEdit();
            if (ktData.update())
            {
				setEditMode(false);
                sendStatus("Đã lưu phiếu thu " + txtSoChungTu.Text  , false);
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdCancel_Click(object sender, System.EventArgs e) {
			bmb.EndCurrentEdit();
            sendStatus("Bỏ qua, không cập nhật", false);
			DialogResult dr = DialogResult.Yes;
            if (ktData.getTable(ChungTuKeToanData.TL.TienMatPT).GetChanges() != null &&
                ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).GetChanges() != null)
            {
				dr = MessageBox.Show(this, RS.CANCEL_UPDATE, RS.CANCEL_UPDATE_CAPTION, 
					MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
			}
			
			if (dr == DialogResult.Yes) {
				cancelHandlers = true;
                ktData.getDataSet().RejectChanges();
				cancelHandlers = false;
				setEditMode(false);
				bmb_PositionChanged(bmb, e);
			}
		}

		FormView fv = null;
		private void cmdView_Click(object sender, System.EventArgs e) {
			if (fv == null) {
				fv = new FormView("Select * from TienMat WHERE MaLoaiChungTu='KT'", GlobalVariable.WSInfo.ConnectionString,
                    GlobalVariable.WSInfo.WorkingDate );
				fv.DateFilterColumns = new string[,] {{"NgayChungTu", "Ngày chứng từ"}, {"UpdateDate", "Ngày cập nhật"}};
                //fv.CollumnFocusInFilterGrid = 4;
			}
			fv.ShowDialog(this);
			if (fv.DialogResult == DialogResult.OK) {
				cancelHandlers = true;
                ktData.initData(fv.SelectedIDs, false);
				setEditMode(false);
				cancelHandlers = false;
				bmb_PositionChanged(bmb, e);
			}			
		}

		private void cmdModify_Click(object sender, System.EventArgs e) {
			if (bmb.Position >= 0) {
				bmb.EndCurrentEdit();
				setEditMode(true);
                sendStatus("Đang trong trạng sửa phiếu thu " + txtSoChungTu.Text  , false);
			}
		}

		private void cmdDelete_Click(object sender, System.EventArgs e) {
			DialogResult dr = MessageBox.Show(this, RS.DELETE_RECORD, RS.DELETE_RECORD_CAPTION, 
				MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
			if (dr == DialogResult.Yes) {
				cancelHandlers = true;
				bmb.RemoveAt(bmb.Position);
                ktData.update();
				cancelHandlers = false;
				bmb_PositionChanged(bmb, e);
			}
		}

		private void cmdPrint_Click(object sender, System.EventArgs e) {
            /*
            //Load report
            ReportDocument rpt = new ReportDocument();
            rpt.Load(Application.StartupPath + "\\Report\\rpt_TienMat_PhieuThu.rpt");

            //Set connection
            PublicFunction.SetDBLogonForReport(rpt);

            //Set parameter
            PublicFunction.SetParameter(rpt, "@Sochungtu", txtSoChungTu.Text);
            PublicFunction.SetParameter(rpt, "pBangchu", ReportUtilities.ReportUtilities.g_Trans_VietNam(Double.Parse(txtSoTien.Text), "đồng", true));
            PublicFunction.SetParameter(rpt, "pNguoilapbieu", GlobalVariable.WSInfo.UserName);
            PublicFunction.SetParameter(rpt, "pThuquy", GlobalVariable.WSInfo["Sys.UserName.Thuquy"]);
            PublicFunction.SetParameter(rpt, "pKetoantruong", GlobalVariable.WSInfo["Sys.UserName.KetoanTruong"]);
            PublicFunction.SetParameter(rpt, "pGiamDoc", GlobalVariable.WSInfo["Sys.UserName.Giamdoc"]);

            //View report
            frmPrintPreview frmPP = new frmPrintPreview(rpt);
            frmPP.ShowDialog();
            frmPP.Dispose();

            rpt.Dispose();
            */
		}


		#endregion

        private void cmdXemTK_Click(object sender, System.EventArgs e) {
            
            if (!cmdAddNew.Enabled && txtSoTien.Text.Trim() == "0") {
				ep.SetError(txtSoTien, "Bạn vui lòng nhập số tiền !.");
				txtSoTien.Focus();
				showEP = true;
				return;
			}
			if (!cmdAddNew.Enabled && txtDonVi.Text == "") {
				ep.SetError(txtDonVi, "Bạn vui lòng chọn đơn vị nộp tiền !.");
				txtDonVi.Focus();
				showEP = true;
				return;
			}


			dgridChiTietPT.Visible = !dgridChiTietPT.Visible;
			if (dgridChiTietPT.Visible) {
				this.Height += 120;
         	} else {
				this.Size = this.MinimumSize;
				this.WindowState = FormWindowState.Normal;
			}
		}


        bool showEP = false;

	
        
		private void txtSoTien_TextChanged(object sender, System.EventArgs e) {
			if (showEP) {
				ep.SetError(txtSoTien, null);
			}
		}

	
		private object this[string colName] {
            get { return ktData.getTable(ChungTuKeToanData.TL.TienMatPT).Rows[bmb.Position][colName]; }
            set { ktData.getTable(ChungTuKeToanData.TL.TienMatPT).Rows[bmb.Position][colName] = value; }
		}

		
		FormView lookupDVNT;
		private void cmdLookupDVNopTiep_Click(object sender, System.EventArgs e) {
			if (lookupDVNT == null) lookupDVNT = new FormView("Select MaDoiTac as [Mã đối tác], TenDoiTac as [Tên đối tác], NguoiDaiDien as [Người đại diện], DiaChi as [Địa chỉ] from DM_DoiTac", GlobalVariable.WSInfo.ConnectionString);
			lookupDVNT.SelectionMode = SelectionMode.One;
			lookupDVNT.addCreateNewAbility("Danh mục Đối tác", GlobalVariable.WSInfo.UserID);
            //lookupDVNT.CollumnFocusInFilterGrid = 1;
			lookupDVNT.ShowDialog(this);
			if (lookupDVNT.DialogResult == DialogResult.OK) {
				txtDonVi.Text = lookupDVNT.SelectedIDs.Replace("('", "").Replace("')","");
				bmb.EndCurrentEdit();
			}
            txtDonVi.Focus();  //De run event Validate
		}

		private void TienMatPhieuThu_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
			if (e.KeyCode == Keys.Enter) {
				this.SelectNextControl(this.ActiveControl, true, true, true, true);
			} else if (e.KeyCode == Keys.Escape) {
				this.SelectNextControl(this.ActiveControl, true, false, true, true);
			}
		}

		private void cmdMoveFirst_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Count > 0) {
				bmb.Position = 0;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdMovePrevious_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Position > 0) {
				bmb.Position -= 1;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdMoveLast_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Count > 0) {
				bmb.Position = bmb.Count -1;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdMoveNext_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Position < bmb.Count -1) {
				bmb.Position += 1;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void sendStatus(string msg) {
			sendStatus(msg, false);
		}

	

		private void cmdNote_Click(object sender, System.EventArgs e) {
			SimpleObjectNote son = new SimpleObjectNote(GlobalVariable.WSInfo.ConnectionString,
				this.Text, GlobalVariable.WSInfo.UserID);
			son.ShowDialog(this);
		}
	
		private void sendStatus(string msg, bool error) {
			if (error) {
				lblStatus.ForeColor = Color.Red;
				lblStatus.Text = msg;
			} else {
				lblStatus.ForeColor = Color.Black;
				lblStatus.Text = msg;
			}
		}



        private void txtDonVi_KeyDown(object sender, KeyEventArgs e)
        {
            if ((txtDonVi.Text == "" && e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.F3))
            {
                cmdLookupDVNopTiep_Click(cmdLookupDVNopTiep, e);
            }
        }

        private void dgridChiTietPT_Validated(object sender, EventArgs e)
        {
            try
            {
                txtSoTien.Text = ((double)(decimal)ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).Compute("Sum(SoTien)", "SoChungTu='" + this["SoChungTu"] + "'")).ToString();
            }
            catch { }
        }

       
       
        private void txtDienGiai_TextChanged(object sender, EventArgs e)
        {
            try
            {
                ktData.getTable(ChungTuKeToanData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D")[0]["DienGiaiChiTiet"] = txtDienGiai.Text;
            }
            catch { }
        }


        private void txtDonVi_Validated(object sender, EventArgs e)
        {
            if (txtDonVi.Text == "") return;
            try
            {
                lblTenDonVi.Text = SQLHelper.ExecuteScalar(GlobalVariable.WSInfo.ConnectionString, "SELECT TenDoiTac FROM DM_DOITAC WHERE MaDoiTac= '" + txtDonVi.Text + "'").ToString();
                txtNguoiDaiDien.Text = SQLHelper.ExecuteScalar(GlobalVariable.WSInfo.ConnectionString, "SELECT NguoiDaiDien FROM DM_DOITAC WHERE MaDoiTac= '" + txtDonVi.Text + "'").ToString();
                txtNguoiDaiDien.Text = CNCSoft.EUtilities.StringUtil.toTitleCase(txtNguoiDaiDien.Text);
                txtDiaChi.Text = SQLHelper.ExecuteScalar(GlobalVariable.WSInfo.ConnectionString, "SELECT DiaChi FROM DM_DOITAC WHERE MaDoiTac= '" + txtDonVi.Text + "'").ToString();
            }
            catch { }

            bmb.EndCurrentEdit();
        }

        private void txtDonVi_TextChanged(object sender, EventArgs e)
        {
            //Can nho: ko viet o day, loi binding bua xua, Viet dong nay trong ChangePosition
            //lblTenDonVi.Text = SQLHelper.ExecuteScalar(GlobalVariable.WSInfo.ConnectionString, "SELECT TenDoiTac FROM DM_DOITAC WHERE MaDoiTac= '" + txtDonVi.Text + "'").ToString();
        }

        private void txtSoTien_Validated(object sender, EventArgs e)
        {
            try
            {
                if (ktData.getTable(ChungTuKeToanData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D").Length == 0)
                {
                    // Add a default row to detail
                    DataRow dr = ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).NewRow();
                    dr["SoChungTu"] = txtSoChungTu.Text;
                    dr["SoTien"] = Double.Parse(txtSoTien.Text);
                    ktData.getTable(ChungTuKeToanData.TL.TienMatPT_CT).Rows.Add(dr);
                }
                else if (ktData.getTable(ChungTuKeToanData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D").Length == 1)
                {
                    ktData.getTable(ChungTuKeToanData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D")[0]["SoTien"] = Double.Parse(txtSoTien.Text);
                }

                bmb.EndCurrentEdit();
            }
            catch (Exception ex)
            {
                sendStatus("Unexpected Error: " + ex.Message, true);
            }
            cancelHandlers = true;

            buildDgridTS();

            cancelHandlers = false; 
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label11_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

  

       

        
        

       

	}
}